package dataStructure.xmg1.a03;

import dataStructure.xmg1.a02.Assert;
import dataStructure.xmg1.a03.circle.CircleLinkedList;
import dataStructure.xmg1.a03.circle.SingleCircleLinkedList;

/**
 * @author: vince_zww
 * @date: 2020/11/4 21:05
 * @desceription:
 */
public class Main {

    static void testList(List<Integer> list) {
        list.add(11);
        list.add(22);
        list.add(33);
        list.add(44);

        list.add(0,55);//[55, 11, 22, 33, 44]
//        System.out.println(list);
        list.add(2,66);//[55, 11, 66, 22, 33, 44]
//        System.out.println(list);
        list.add(list.size(),77);//[55, 11, 22, 33, 44, 77]
//        System.out.println(list);
        list.remove(0);
        list.remove(2);
        list.remove(list.size() - 1);

        Asserts.test(list.indexOf(44) == 3);
        Asserts.test(list.indexOf(22) == List.ELEMENT_NOT_FOUND);
        Asserts.test(list.contains(33));
        Asserts.test(list.get(0)==11);
        Asserts.test(list.get(1)==66);
        Asserts.test(list.get(list.size()-1)==44);

//        for (int i = 0; i < 30; i++) {
//            list.add(i);
//        }
        System.out.println(list.toString());
    }


    public static void main(String[] args) {
//        testList(new CircleLinkedList<>());
        josepphus();
    }


    private void test01() {
        //        List<Integer> list = new LinkedList2<>();
//        list.add(20);
//        list.add(0,10);
//        list.add(30);
//        list.add(list.size(), 40);
//        //10,30,40
//        list.remove(1);


        List<Integer> list = new ArrayList2<>();
        for (int i = 0; i < 50; i++) {
            list.add(i);
        }
        for (int i = 0; i < 50; i++) {
            list.remove(0);
        }

        System.out.println(list);
    }

    private void test02(){
        testList(new ArrayList<>());
        testList(new LinkedList<>());
        testList(new CircleLinkedList<>());
    }

    static void josepphus(){
        CircleLinkedList<Integer> list = new CircleLinkedList<>();
        for (int i = 1; i <= 8; i++) {
            list.add(i);
        }


        list.reset();
        while (!list.isEmpty()) {
            list.next();
            list.next();
            System.out.println(list.remove());
        }

    }
}
